home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 March / maximum-cd-2000-03.iso / Quake3 Game Source / Q3AGameSource.exe / Main / q_shared.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-18  |  28.0 KB  |  948 lines

  1. // Copyright (C) 1999-2000 Id Software, Inc.
  2. //
  3. #ifndef __Q_SHARED_H
  4. #define __Q_SHARED_H
  5.  
  6. // q_shared.h -- included first by ALL program modules.
  7. // A user mod should never modify this file
  8.  
  9. #define    Q3_VERSION        "Q3 1.15c"
  10.  
  11. #ifdef _WIN32
  12.  
  13. #pragma warning(disable : 4018)     // signed/unsigned mismatch
  14. #pragma warning(disable : 4032)
  15. #pragma warning(disable : 4051)
  16. #pragma warning(disable : 4057)        // slightly different base types
  17. #pragma warning(disable : 4100)        // unreferenced formal parameter
  18. #pragma warning(disable : 4115)
  19. #pragma warning(disable : 4125)        // decimal digit terminates octal escape sequence
  20. #pragma warning(disable : 4127)        // conditional expression is constant
  21. #pragma warning(disable : 4136)
  22. #pragma warning(disable : 4201)
  23. #pragma warning(disable : 4214)
  24. #pragma warning(disable : 4244)
  25. #pragma warning(disable : 4305)        // truncation from const double to float
  26. #pragma warning(disable : 4310)        // cast truncates constant value
  27. #pragma warning(disable : 4514)
  28. #pragma warning(disable : 4711)        // selected for automatic inline expansion
  29. #pragma warning(disable : 4220)        // varargs matches remaining parameters
  30.  
  31. #endif
  32.  
  33. #include <assert.h>
  34. #include <math.h>
  35. #include <stdio.h>
  36. #include <stdarg.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <time.h>
  40. #include <ctype.h>
  41.  
  42. #ifdef _WIN32
  43.  
  44. //#pragma intrinsic( memset, memcpy )
  45.  
  46. #endif
  47.  
  48.  
  49. // this is the define for determining if we have an asm version of a C function
  50. #if (defined _M_IX86 || defined __i386__) && !defined __sun__  && !defined __LCC__
  51. #define id386    1
  52. #else
  53. #define id386    0
  54. #endif
  55.  
  56. // for windows fastcall option
  57.  
  58. #define    QDECL
  59.  
  60. //======================= WIN32 DEFINES =================================
  61.  
  62. #ifdef WIN32
  63.  
  64. #define    MAC_STATIC
  65.  
  66. #undef QDECL
  67. #define    QDECL    __cdecl
  68.  
  69. // buildstring will be incorporated into the version string
  70. #ifdef NDEBUG
  71. #ifdef _M_IX86
  72. #define    CPUSTRING    "win-x86"
  73. #elif defined _M_ALPHA
  74. #define    CPUSTRING    "win-AXP"
  75. #endif
  76. #else
  77. #ifdef _M_IX86
  78. #define    CPUSTRING    "win-x86-debug"
  79. #elif defined _M_ALPHA
  80. #define    CPUSTRING    "win-AXP-debug"
  81. #endif
  82. #endif
  83.  
  84.  
  85. #define    PATH_SEP '\\'
  86.  
  87. #endif
  88.  
  89. //======================= MAC OS X SERVER DEFINES =====================
  90.  
  91. #if defined(__MACH__) && defined(__APPLE__)
  92.  
  93. #define MAC_STATIC
  94.  
  95. #ifdef __ppc__
  96. #define CPUSTRING    "MacOSXS-ppc"
  97. #elif defined __i386__
  98. #define CPUSTRING    "MacOSXS-i386"
  99. #else
  100. #define CPUSTRING    "MacOSXS-other"
  101. #endif
  102.  
  103. #define    PATH_SEP    '/'
  104.  
  105. #define    GAME_HARD_LINKED
  106. #define    CGAME_HARD_LINKED
  107. #define    UI_HARD_LINKED
  108. #define    BOTLIB_HARD_LINKED
  109.  
  110. #endif
  111.  
  112. //======================= MAC DEFINES =================================
  113.  
  114. #ifdef __MACOS__
  115.  
  116. #define    MAC_STATIC    static
  117.  
  118. #define    CPUSTRING    "MacOS-PPC"
  119.  
  120. #define    PATH_SEP ':'
  121.  
  122. #define    GAME_HARD_LINKED
  123. #define    CGAME_HARD_LINKED
  124. #define    UI_HARD_LINKED
  125. #define    BOTLIB_HARD_LINKED
  126.  
  127. void Sys_PumpEvents( void );
  128.  
  129. #endif
  130.  
  131. //======================= LINUX DEFINES =================================
  132.  
  133. // the mac compiler can't handle >32k of locals, so we
  134. // just waste space and make big arrays static...
  135. #ifdef __linux__
  136.  
  137. #define    MAC_STATIC
  138.  
  139. #ifdef __i386__
  140. #define    CPUSTRING    "linux-i386"
  141. #elif defined __axp__
  142. #define    CPUSTRING    "linux-alpha"
  143. #else
  144. #define    CPUSTRING    "linux-other"
  145. #endif
  146.  
  147. #define    PATH_SEP '/'
  148.  
  149. #endif
  150.  
  151. //=============================================================
  152.  
  153.  
  154. typedef unsigned char         byte;
  155.  
  156. typedef enum {qfalse, qtrue}    qboolean;
  157.  
  158. typedef int        qhandle_t;
  159. typedef int        sfxHandle_t;
  160. typedef int        fileHandle_t;
  161. typedef int        clipHandle_t;
  162.  
  163.  
  164. #ifndef NULL
  165. #define NULL ((void *)0)
  166. #endif
  167.  
  168. #define    MAX_QINT            0x7fffffff
  169. #define    MIN_QINT            (-MAX_QINT-1)
  170.  
  171.  
  172. // angle indexes
  173. #define    PITCH                0        // up / down
  174. #define    YAW                    1        // left / right
  175. #define    ROLL                2        // fall over
  176.  
  177. // the game guarantees that no string from the network will ever
  178. // exceed MAX_STRING_CHARS
  179. #define    MAX_STRING_CHARS    1024    // max length of a string passed to Cmd_TokenizeString
  180. #define    MAX_STRING_TOKENS    256        // max tokens resulting from Cmd_TokenizeString
  181. #define    MAX_TOKEN_CHARS        1024    // max length of an individual token
  182.  
  183. #define    MAX_INFO_STRING        1024
  184. #define    MAX_INFO_KEY        1024
  185. #define    MAX_INFO_VALUE        1024
  186.  
  187.  
  188. #define    MAX_QPATH            64        // max length of a quake game pathname
  189. #define    MAX_OSPATH            128        // max length of a filesystem pathname
  190.  
  191. #define    MAX_NAME_LENGTH        32        // max length of a client name
  192.  
  193. // paramters for command buffer stuffing
  194. typedef enum {
  195.     EXEC_NOW,            // don't return until completed, a VM should NEVER use this,
  196.                         // because some commands might cause the VM to be unloaded...
  197.     EXEC_INSERT,        // insert at current position, but don't run yet
  198.     EXEC_APPEND            // add to end of the command buffer (normal case)
  199. } cbufExec_t;
  200.  
  201.  
  202. //
  203. // these aren't needed by any of the VMs.  put in another header?
  204. //
  205. #define    MAX_MAP_AREA_BYTES        32        // bit vector of area visibility
  206.  
  207.  
  208. // print levels from renderer (FIXME: set up for game / cgame?)
  209. typedef enum {
  210.     PRINT_ALL,
  211.     PRINT_DEVELOPER,        // only print when "developer 1"
  212.     PRINT_WARNING,
  213.     PRINT_ERROR
  214. } printParm_t;
  215.  
  216.  
  217. // parameters to the main Error routine
  218. typedef enum {
  219.     ERR_FATAL,                    // exit the entire game with a popup window
  220.     ERR_DROP,                    // print to console and disconnect from game
  221.     ERR_DISCONNECT,                // don't kill server
  222.     ERR_NEED_CD                    // pop up the need-cd dialog
  223. } errorParm_t;
  224.  
  225.  
  226. // font rendering values used by ui and cgame
  227.  
  228. #define PROP_GAP_WIDTH            3
  229. #define PROP_SPACE_WIDTH        8
  230. #define PROP_HEIGHT                27
  231. #define PROP_SMALL_SIZE_SCALE    0.75
  232.  
  233. #define BLINK_DIVISOR            200
  234. #define PULSE_DIVISOR            75
  235.  
  236. #define UI_LEFT            0x00000000    // default
  237. #define UI_CENTER        0x00000001
  238. #define UI_RIGHT        0x00000002
  239. #define UI_FORMATMASK    0x00000007
  240. #define UI_SMALLFONT    0x00000010
  241. #define UI_BIGFONT        0x00000020    // default
  242. #define UI_GIANTFONT    0x00000040
  243. #define UI_DROPSHADOW    0x00000800
  244. #define UI_BLINK        0x00001000
  245. #define UI_INVERSE        0x00002000
  246. #define UI_PULSE        0x00004000
  247.  
  248.  
  249. /*
  250. ==============================================================
  251.  
  252. MATHLIB
  253.  
  254. ==============================================================
  255. */
  256.  
  257.  
  258. typedef float vec_t;
  259. typedef vec_t vec2_t[2];
  260. typedef vec_t vec3_t[3];
  261. typedef vec_t vec4_t[4];
  262. typedef vec_t vec5_t[5];
  263.  
  264. typedef    int    fixed4_t;
  265. typedef    int    fixed8_t;
  266. typedef    int    fixed16_t;
  267.  
  268. #ifndef M_PI
  269. #define M_PI        3.14159265358979323846    // matches value in gcc v2 math.h
  270. #endif
  271.  
  272. #define NUMVERTEXNORMALS    162
  273. extern    vec3_t    bytedirs[NUMVERTEXNORMALS];
  274.  
  275. // all drawing is done to a 640*480 virtual screen size
  276. // and will be automatically scaled to the real resolution
  277. #define    SCREEN_WIDTH        640
  278. #define    SCREEN_HEIGHT        480
  279.  
  280. #define TINYCHAR_WIDTH        (SMALLCHAR_WIDTH)
  281. #define TINYCHAR_HEIGHT        (SMALLCHAR_HEIGHT/2)
  282.  
  283. #define SMALLCHAR_WIDTH        8
  284. #define SMALLCHAR_HEIGHT    16
  285.  
  286. #define BIGCHAR_WIDTH        16
  287. #define BIGCHAR_HEIGHT        16
  288.  
  289. #define    GIANTCHAR_WIDTH        32
  290. #define    GIANTCHAR_HEIGHT    48
  291.  
  292. extern    vec4_t        colorBlack;
  293. extern    vec4_t        colorRed;
  294. extern    vec4_t        colorGreen;
  295. extern    vec4_t        colorBlue;
  296. extern    vec4_t        colorYellow;
  297. extern    vec4_t        colorMagenta;
  298. extern    vec4_t        colorCyan;
  299. extern    vec4_t        colorWhite;
  300. extern    vec4_t        colorLtGrey;
  301. extern    vec4_t        colorMdGrey;
  302. extern    vec4_t        colorDkGrey;
  303.  
  304. #define Q_COLOR_ESCAPE    '^'
  305. #define Q_IsColorString(p)    ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE )
  306.  
  307. #define COLOR_BLACK        '0'
  308. #define COLOR_RED        '1'
  309. #define COLOR_GREEN        '2'
  310. #define COLOR_YELLOW    '3'
  311. #define COLOR_BLUE        '4'
  312. #define COLOR_CYAN        '5'
  313. #define COLOR_MAGENTA    '6'
  314. #define COLOR_WHITE        '7'
  315. #define ColorIndex(c)    ( ( (c) - '0' ) & 7 )
  316.  
  317. #define S_COLOR_BLACK    "^0"
  318. #define S_COLOR_RED        "^1"
  319. #define S_COLOR_GREEN    "^2"
  320. #define S_COLOR_YELLOW    "^3"
  321. #define S_COLOR_BLUE    "^4"
  322. #define S_COLOR_CYAN    "^5"
  323. #define S_COLOR_MAGENTA    "^6"
  324. #define S_COLOR_WHITE    "^7"
  325.  
  326. extern vec4_t    g_color_table[8];
  327.  
  328. #define    MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
  329. #define    MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
  330.  
  331. #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
  332. #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
  333.  
  334. struct cplane_s;
  335.  
  336. extern    vec3_t    vec3_origin;
  337. extern    vec3_t    axisDefault[3];
  338.  
  339. #define    nanmask (255<<23)
  340.  
  341. #define    IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
  342.  
  343. float Q_fabs( float f );
  344. float Q_rsqrt( float f );        // reciprocal square root
  345.  
  346. #define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) )
  347.  
  348. signed char ClampChar( int i );
  349. signed short ClampShort( int i );
  350.  
  351. // this isn't a real cheap function to call!
  352. int DirToByte( vec3_t dir );
  353. void ByteToDir( int b, vec3_t dir );
  354.  
  355. #if    1
  356.  
  357. #define DotProduct(x,y)            ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
  358. #define VectorSubtract(a,b,c)    ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
  359. #define VectorAdd(a,b,c)        ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
  360. #define VectorCopy(a,b)            ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
  361. #define    VectorScale(v, s, o)    ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
  362. #define    VectorMA(v, s, b, o)    ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
  363.  
  364. #else
  365.  
  366. #define DotProduct(x,y)            _DotProduct(x,y)
  367. #define VectorSubtract(a,b,c)    _VectorSubtract(a,b,c)
  368. #define VectorAdd(a,b,c)        _VectorAdd(a,b,c)
  369. #define VectorCopy(a,b)            _VectorCopy(a,b)
  370. #define    VectorScale(v, s, o)    _VectorScale(v,s,o)
  371. #define    VectorMA(v, s, b, o)    _VectorMA(v,s,b,o)
  372.  
  373. #endif
  374.  
  375. #ifdef __LCC__
  376. #ifdef VectorCopy
  377. #undef VectorCopy
  378. // this is a little hack to get more efficient copies in our interpreter
  379. typedef struct {
  380.     float    v[3];
  381. } vec3struct_t;
  382. #define VectorCopy(a,b)    *(vec3struct_t *)b=*(vec3struct_t *)a;
  383. #endif
  384. #endif
  385.  
  386. #define VectorClear(a)            ((a)[0]=(a)[1]=(a)[2]=0)
  387. #define VectorNegate(a,b)        ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
  388. #define VectorSet(v, x, y, z)    ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
  389. #define Vector4Copy(a,b)        ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
  390.  
  391. #define    SnapVector(v) {v[0]=(int)v[0];v[1]=(int)v[1];v[2]=(int)v[2];}
  392.  
  393. // just in case you do't want to use the macros
  394. vec_t _DotProduct( const vec3_t v1, const vec3_t v2 );
  395. void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out );
  396. void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out );
  397. void _VectorCopy( const vec3_t in, vec3_t out );
  398. void _VectorScale( const vec3_t in, float scale, vec3_t out );
  399. void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc );
  400.  
  401. unsigned ColorBytes3 (float r, float g, float b);
  402. unsigned ColorBytes4 (float r, float g, float b, float a);
  403.  
  404. float NormalizeColor( const vec3_t in, vec3_t out );
  405.  
  406. float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
  407. void ClearBounds( vec3_t mins, vec3_t maxs );
  408. void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
  409. int VectorCompare( const vec3_t v1, const vec3_t v2 );
  410. vec_t VectorLength( const vec3_t v );
  411. vec_t Distance( const vec3_t p1, const vec3_t p2 );
  412. vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 );
  413. void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
  414. vec_t VectorNormalize (vec3_t v);        // returns vector length
  415. void VectorNormalizeFast(vec3_t v);        // does NOT return vector length, uses rsqrt approximation
  416. vec_t VectorNormalize2( const vec3_t v, vec3_t out );
  417. void VectorInverse (vec3_t v);
  418. void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out );
  419. void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out );
  420. int Q_log2(int val);
  421.  
  422. int        Q_rand( int *seed );
  423. float    Q_random( int *seed );
  424. float    Q_crandom( int *seed );
  425.  
  426. #define random()    ((rand () & 0x7fff) / ((float)0x7fff))
  427. #define crandom()    (2.0 * (random() - 0.5))
  428.  
  429. void vectoangles( const vec3_t value1, vec3_t angles);
  430. void AnglesToAxis( const vec3_t angles, vec3_t axis[3] );
  431.  
  432. void AxisClear( vec3_t axis[3] );
  433. void AxisCopy( vec3_t in[3], vec3_t out[3] );
  434.  
  435. void SetPlaneSignbits( struct cplane_s *out );
  436. int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
  437.  
  438. float    AngleMod(float a);
  439. float    LerpAngle (float from, float to, float frac);
  440. float    AngleSubtract( float a1, float a2 );
  441. void    AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 );
  442.  
  443. float AngleNormalize360 ( float angle );
  444. float AngleNormalize180 ( float angle );
  445. float AngleDelta ( float angle1, float angle2 );
  446.  
  447. qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
  448. void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
  449. void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
  450. void RotateAroundDirection( vec3_t axis[3], float yaw );
  451. void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up );
  452. // perpendicular vector could be replaced by this
  453.  
  454. int    PlaneTypeForNormal (vec3_t normal);
  455.  
  456. void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]);
  457. void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
  458. void PerpendicularVector( vec3_t dst, const vec3_t src );
  459.  
  460.  
  461. //=============================================
  462.  
  463. float Com_Clamp( float min, float max, float value );
  464.  
  465. char    *COM_SkipPath( char *pathname );
  466. void    COM_StripExtension( const char *in, char *out );
  467. void    COM_DefaultExtension( char *path, int maxSize, const char *extension );
  468.  
  469. void    COM_BeginParseSession( void );
  470. int        COM_GetCurrentParseLine( void );
  471. char    *COM_Parse( char **data_p );
  472. char    *COM_ParseExt( char **data_p, qboolean allowLineBreak );
  473. //int        COM_ParseInfos( char *buf, int max, char infos[][MAX_INFO_STRING] );
  474.  
  475. // data is an in/out parm, returns a parsed out token
  476.  
  477. void    COM_MatchToken( char**buf_p, char *match );
  478.  
  479. void SkipBracedSection (char **program);
  480. void SkipRestOfLine ( char **data );
  481.  
  482. void Parse1DMatrix (char **buf_p, int x, float *m);
  483. void Parse2DMatrix (char **buf_p, int y, int x, float *m);
  484. void Parse3DMatrix (char **buf_p, int z, int y, int x, float *m);
  485.  
  486. void    QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
  487.  
  488.  
  489. // mode parm for FS_FOpenFile
  490. typedef enum {
  491.     FS_READ,
  492.     FS_WRITE,
  493.     FS_APPEND,
  494.     FS_APPEND_SYNC
  495. } fsMode_t;
  496.  
  497. typedef enum {
  498.     FS_SEEK_CUR,
  499.     FS_SEEK_END,
  500.     FS_SEEK_SET
  501. } fsOrigin_t;
  502.  
  503. //=============================================
  504.  
  505. int Q_isprint( int c );
  506. int Q_islower( int c );
  507. int Q_isupper( int c );
  508. int Q_isalpha( int c );
  509.  
  510. // portable case insensitive compare
  511. int        Q_stricmp (const char *s1, const char *s2);
  512. int        Q_strncmp (const char *s1, const char *s2, int n);
  513. int        Q_stricmpn (const char *s1, const char *s2, int n);
  514. char    *Q_strlwr( char *s1 );
  515. char    *Q_strupr( char *s1 );
  516. char    *Q_strrchr( const char* string, int c );
  517.  
  518. // buffer size safe library replacements
  519. void    Q_strncpyz( char *dest, const char *src, int destsize );
  520. void    Q_strcat( char *dest, int size, const char *src );
  521.  
  522. // strlen that discounts Quake color sequences
  523. int Q_PrintStrlen( const char *string );
  524. // removes color sequences from string
  525. char *Q_CleanStr( char *string );
  526.  
  527. //=============================================
  528.  
  529. short    BigShort(short l);
  530. short    LittleShort(short l);
  531. int        BigLong (int l);
  532. int        LittleLong (int l);
  533. float    BigFloat (float l);
  534. float    LittleFloat (float l);
  535.  
  536. void    Swap_Init (void);
  537. char    * QDECL va(char *format, ...);
  538.  
  539. //=============================================
  540.  
  541. //
  542. // key / value info strings
  543. //
  544. char *Info_ValueForKey( const char *s, const char *key );
  545. void Info_RemoveKey( char *s, const char *key );
  546. void Info_SetValueForKey( char *s, const char *key, const char *value );
  547. qboolean Info_Validate( const char *s );
  548. void Info_NextPair( const char **s, char key[MAX_INFO_KEY], char value[MAX_INFO_VALUE] );
  549.  
  550. // this is only here so the functions in q_shared.c and bg_*.c can link
  551. void    QDECL Com_Error( int level, const char *error, ... );
  552. void    QDECL Com_Printf( const char *msg, ... );
  553.  
  554.  
  555. /*
  556. ==========================================================
  557.  
  558. CVARS (console variables)
  559.  
  560. Many variables can be used for cheating purposes, so when
  561. cheats is zero, force all unspecified variables to their
  562. default values.
  563. ==========================================================
  564. */
  565.  
  566. #define    CVAR_ARCHIVE        1    // set to cause it to be saved to vars.rc
  567.                                 // used for system variables, not for player
  568.                                 // specific configurations
  569. #define    CVAR_USERINFO        2    // sent to server on connect or change
  570. #define    CVAR_SERVERINFO        4    // sent in response to front end requests
  571. #define    CVAR_SYSTEMINFO        8    // these cvars will be duplicated on all clients
  572. #define    CVAR_INIT            16    // don't allow change from console at all,
  573.                                 // but can be set from the command line
  574. #define    CVAR_LATCH            32    // will only change when C code next does
  575.                                 // a Cvar_Get(), so it can't be changed
  576.                                 // without proper initialization.  modified
  577.                                 // will be set, even though the value hasn't
  578.                                 // changed yet
  579. #define    CVAR_ROM            64    // display only, cannot be set by user at all
  580. #define    CVAR_USER_CREATED    128    // created by a set command
  581. #define    CVAR_TEMP            256    // can be set even when cheats are disabled, but is not archived
  582. #define CVAR_CHEAT            512    // can not be changed if cheats are disabled
  583. #define CVAR_NORESTART        1024    // do not clear when a cvar_restart is issued
  584.  
  585. // nothing outside the Cvar_*() functions should modify these fields!
  586. typedef struct cvar_s {
  587.     char        *name;
  588.     char        *string;
  589.     char        *resetString;        // cvar_restart will reset to this value
  590.     char        *latchedString;        // for CVAR_LATCH vars
  591.     int            flags;
  592.     qboolean    modified;            // set each time the cvar is changed
  593.     int            modificationCount;    // incremented each time the cvar is changed
  594.     float        value;                // atof( string )
  595.     int            integer;            // atoi( string )
  596.     struct cvar_s *next;
  597. } cvar_t;
  598.  
  599. #define    MAX_CVAR_VALUE_STRING    256
  600.  
  601. typedef int    cvarHandle_t;
  602.  
  603. // the modules that run in the virtual machine can't access the cvar_t directly,
  604. // so they must ask for structured updates
  605. typedef struct {
  606.     cvarHandle_t    handle;
  607.     int            modificationCount;
  608.     float        value;
  609.     int            integer;
  610.     char        string[MAX_CVAR_VALUE_STRING];
  611. } vmCvar_t;
  612.  
  613. /*
  614. ==============================================================
  615.  
  616. COLLISION DETECTION
  617.  
  618. ==============================================================
  619. */
  620.  
  621. #include "surfaceflags.h"            // shared with the q3map utility
  622.  
  623. // plane types are used to speed some tests
  624. // 0-2 are axial planes
  625. #define    PLANE_X            0
  626. #define    PLANE_Y            1
  627. #define    PLANE_Z            2
  628. #define    PLANE_NON_AXIAL    3
  629.  
  630.  
  631. // plane_t structure
  632. // !!! if this is changed, it must be changed in asm code too !!!
  633. typedef struct cplane_s {
  634.     vec3_t    normal;
  635.     float    dist;
  636.     byte    type;            // for fast side tests: 0,1,2 = axial, 3 = nonaxial
  637.     byte    signbits;        // signx + (signy<<1) + (signz<<2), used as lookup during collision
  638.     byte    pad[2];
  639. } cplane_t;
  640.  
  641.  
  642. // a trace is returned when a box is swept through the world
  643. typedef struct {
  644.     qboolean    allsolid;    // if true, plane is not valid
  645.     qboolean    startsolid;    // if true, the initial point was in a solid area
  646.     float        fraction;    // time completed, 1.0 = didn't hit anything
  647.     vec3_t        endpos;        // final position
  648.     cplane_t    plane;        // surface normal at impact, transformed to world space
  649.     int            surfaceFlags;    // surface hit
  650.     int            contents;    // contents on other side of surface hit
  651.     int            entityNum;    // entity the contacted sirface is a part of
  652. } trace_t;
  653.  
  654. // trace->entityNum can also be 0 to (MAX_GENTITIES-1)
  655. // or ENTITYNUM_NONE, ENTITYNUM_WORLD
  656.  
  657.  
  658. // markfragments are returned by CM_MarkFragments()
  659. typedef struct {
  660.     int        firstPoint;
  661.     int        numPoints;
  662. } markFragment_t;
  663.  
  664.  
  665.  
  666. typedef struct {
  667.     vec3_t        origin;
  668.     vec3_t        axis[3];
  669. } orientation_t;
  670.  
  671. //=====================================================================
  672.  
  673.  
  674. // in order from highest priority to lowest
  675. // if none of the catchers are active, bound key strings will be executed
  676. #define KEYCATCH_CONSOLE    1
  677. #define    KEYCATCH_UI            2
  678. #define    KEYCATCH_MESSAGE    4
  679.  
  680.  
  681. // sound channels
  682. // channel 0 never willingly overrides
  683. // other channels will allways override a playing sound on that channel
  684. typedef enum {
  685.     CHAN_AUTO,
  686.     CHAN_LOCAL,        // menu sounds, etc
  687.     CHAN_WEAPON,
  688.     CHAN_VOICE,
  689.     CHAN_ITEM,
  690.     CHAN_BODY,
  691.     CHAN_LOCAL_SOUND,    // chat messages, etc
  692.     CHAN_ANNOUNCER        // announcer voices, etc
  693. } soundChannel_t;
  694.  
  695.  
  696. /*
  697. ========================================================================
  698.  
  699.   ELEMENTS COMMUNICATED ACROSS THE NET
  700.  
  701. ========================================================================
  702. */
  703.  
  704. #define    ANGLE2SHORT(x)    ((int)((x)*65536/360) & 65535)
  705. #define    SHORT2ANGLE(x)    ((x)*(360.0/65536))
  706.  
  707. #define    SNAPFLAG_RATE_DELAYED    1
  708. #define    SNAPFLAG_NOT_ACTIVE        2    // snapshot used during connection and for zombies
  709. #define SNAPFLAG_SERVERCOUNT    4    // toggled every map_restart so transitions can be detected
  710.  
  711. //
  712. // per-level limits
  713. //
  714. #define    MAX_CLIENTS            128        // absolute limit
  715. #define MAX_LOCATIONS        64
  716.  
  717. #define    GENTITYNUM_BITS        10        // don't need to send any more
  718. #define    MAX_GENTITIES        (1<<GENTITYNUM_BITS)
  719.  
  720. // entitynums are communicated with GENTITY_BITS, so any reserved
  721. // values thatare going to be communcated over the net need to
  722. // also be in this range
  723. #define    ENTITYNUM_NONE        (MAX_GENTITIES-1)
  724. #define    ENTITYNUM_WORLD        (MAX_GENTITIES-2)
  725. #define    ENTITYNUM_MAX_NORMAL    (MAX_GENTITIES-2)
  726.  
  727.  
  728. #define    MAX_MODELS            256        // these are sent over the net as 8 bits
  729. #define    MAX_SOUNDS            256        // so they cannot be blindly increased
  730.  
  731.  
  732. #define    MAX_CONFIGSTRINGS    1024
  733.  
  734. // these are the only configstrings that the system reserves, all the
  735. // other ones are strictly for servergame to clientgame communication
  736. #define    CS_SERVERINFO        0        // an info string with all the serverinfo cvars
  737. #define    CS_SYSTEMINFO        1        // an info string for server system to client system configuration (timescale, etc)
  738.  
  739. #define    RESERVED_CONFIGSTRINGS    2    // game can't modify below this, only the system can
  740.  
  741. #define    MAX_GAMESTATE_CHARS    16000
  742. typedef struct {
  743.     int            stringOffsets[MAX_CONFIGSTRINGS];
  744.     char        stringData[MAX_GAMESTATE_CHARS];
  745.     int            dataCount;
  746. } gameState_t;
  747.  
  748. //=========================================================
  749.  
  750. // bit field limits
  751. #define    MAX_STATS                16
  752. #define    MAX_PERSISTANT            16
  753. #define    MAX_POWERUPS            16
  754. #define    MAX_WEAPONS                16        
  755.  
  756. #define    MAX_PS_EVENTS            2
  757.  
  758. // playerState_t is the information needed by both the client and server
  759. // to predict player motion and actions
  760. // nothing outside of pmove should modify these, or some degree of prediction error
  761. // will occur
  762.  
  763. // you can't add anything to this without modifying the code in msg.c
  764.  
  765. // playerState_t is a full superset of entityState_t as it is used by players,
  766. // so if a playerState_t is transmitted, the entityState_t can be fully derived
  767. // from it.
  768. typedef struct playerState_s {
  769.     int            commandTime;    // cmd->serverTime of last executed command
  770.     int            pm_type;
  771.     int            bobCycle;        // for view bobbing and footstep generation
  772.     int            pm_flags;        // ducked, jump_held, etc
  773.     int            pm_time;
  774.  
  775.     vec3_t        origin;
  776.     vec3_t        velocity;
  777.     int            weaponTime;
  778.     int            gravity;
  779.     int            speed;
  780.     int            delta_angles[3];    // add to command angles to get view direction
  781.                                     // changed by spawns, rotating objects, and teleporters
  782.  
  783.     int            groundEntityNum;// ENTITYNUM_NONE = in air
  784.  
  785.     int            legsTimer;        // don't change low priority animations until this runs out
  786.     int            legsAnim;        // mask off ANIM_TOGGLEBIT
  787.  
  788.     int            torsoTimer;        // don't change low priority animations until this runs out
  789.     int            torsoAnim;        // mask off ANIM_TOGGLEBIT
  790.  
  791.     int            movementDir;    // a number 0 to 7 that represents the reletive angle
  792.                                 // of movement to the view angle (axial and diagonals)
  793.                                 // when at rest, the value will remain unchanged
  794.                                 // used to twist the legs during strafing
  795.  
  796.     vec3_t        grapplePoint;    // location of grapple to pull towards if PMF_GRAPPLE_PULL
  797.  
  798.     int            eFlags;            // copied to entityState_t->eFlags
  799.  
  800.     int            eventSequence;    // pmove generated events
  801.     int            events[MAX_PS_EVENTS];
  802.     int            eventParms[MAX_PS_EVENTS];
  803.  
  804.     int            externalEvent;    // events set on player from another source
  805.     int            externalEventParm;
  806.     int            externalEventTime;
  807.  
  808.     int            clientNum;        // ranges from 0 to MAX_CLIENTS-1
  809.     int            weapon;            // copied to entityState_t->weapon
  810.     int            weaponstate;
  811.  
  812.     vec3_t        viewangles;        // for fixed views
  813.     int            viewheight;
  814.  
  815.     // damage feedback
  816.     int            damageEvent;    // when it changes, latch the other parms
  817.     int            damageYaw;
  818.     int            damagePitch;
  819.     int            damageCount;
  820.  
  821.     int            stats[MAX_STATS];
  822.     int            persistant[MAX_PERSISTANT];    // stats that aren't cleared on death
  823.     int            powerups[MAX_POWERUPS];    // level.time that the powerup runs out
  824.     int            ammo[MAX_WEAPONS];
  825.  
  826.     // not communicated over the net at all
  827.     int            ping;            // server to game info for scoreboard
  828. } playerState_t;
  829.  
  830.  
  831. //====================================================================
  832.  
  833.  
  834. //
  835. // usercmd_t->button bits, many of which are generated by the client system,
  836. // so they aren't game/cgame only definitions
  837. //
  838. #define    BUTTON_ATTACK        1
  839. #define    BUTTON_TALK            2            // displays talk balloon and disables actions
  840. #define    BUTTON_USE_HOLDABLE    4
  841. #define    BUTTON_GESTURE        8
  842. #define    BUTTON_WALKING        16            // walking can't just be infered from MOVE_RUN
  843.                                         // because a key pressed late in the frame will
  844.                                         // only generate a small move value for that frame
  845.                                         // walking will use different animations and
  846.                                         // won't generate footsteps
  847. #define    BUTTON_ANY            128            // any key whatsoever
  848.  
  849. #define    MOVE_RUN            120            // if forwardmove or rightmove are >= MOVE_RUN,
  850.                                         // then BUTTON_WALKING should be set
  851.  
  852.  
  853. // usercmd_t is sent to the server each client frame
  854. typedef struct usercmd_s {
  855.     int        serverTime;
  856.     byte    buttons;
  857.     byte    weapon;
  858.     int        angles[3];
  859.     signed char    forwardmove, rightmove, upmove;
  860. } usercmd_t;
  861.  
  862. //===================================================================
  863.  
  864. // if entityState->solid == SOLID_BMODEL, modelindex is an inline model number
  865. #define    SOLID_BMODEL    0xffffff
  866.  
  867. typedef enum {
  868.     TR_STATIONARY,
  869.     TR_INTERPOLATE,                // non-parametric, but interpolate between snapshots
  870.     TR_LINEAR,
  871.     TR_LINEAR_STOP,
  872.     TR_SINE,                    // value = base + sin( time / duration ) * delta
  873.     TR_GRAVITY
  874. } trType_t;
  875.  
  876. typedef struct {
  877.     trType_t    trType;
  878.     int        trTime;
  879.     int        trDuration;            // if non 0, trTime + trDuration = stop time
  880.     vec3_t    trBase;
  881.     vec3_t    trDelta;            // velocity, etc
  882. } trajectory_t;
  883.  
  884. // entityState_t is the information conveyed from the server
  885. // in an update message about entities that the client will
  886. // need to render in some way
  887. // Different eTypes may use the information in different ways
  888. // The messages are delta compressed, so it doesn't really matter if
  889. // the structure size is fairly large
  890.  
  891. typedef struct entityState_s {
  892.     int        number;            // entity index
  893.     int        eType;            // entityType_t
  894.     int        eFlags;
  895.  
  896.     trajectory_t    pos;    // for calculating position
  897.     trajectory_t    apos;    // for calculating angles
  898.  
  899.     int        time;
  900.     int        time2;
  901.  
  902.     vec3_t    origin;
  903.     vec3_t    origin2;
  904.  
  905.     vec3_t    angles;
  906.     vec3_t    angles2;
  907.  
  908.     int        otherEntityNum;    // shotgun sources, etc
  909.     int        otherEntityNum2;
  910.  
  911.     int        groundEntityNum;    // -1 = in air
  912.  
  913.     int        constantLight;    // r + (g<<8) + (b<<16) + (intensity<<24)
  914.     int        loopSound;        // constantly loop this sound
  915.  
  916.     int        modelindex;
  917.     int        modelindex2;
  918.     int        clientNum;        // 0 to (MAX_CLIENTS - 1), for players and corpses
  919.     int        frame;
  920.  
  921.     int        solid;            // for client side prediction, trap_linkentity sets this properly
  922.  
  923.     int        event;            // impulse events -- muzzle flashes, footsteps, etc
  924.     int        eventParm;
  925.  
  926.     // for players
  927.     int        powerups;        // bit flags
  928.     int        weapon;            // determines weapon and flash model, etc
  929.     int        legsAnim;        // mask off ANIM_TOGGLEBIT
  930.     int        torsoAnim;        // mask off ANIM_TOGGLEBIT
  931. } entityState_t;
  932.  
  933. typedef enum {
  934.     CA_UNINITIALIZED,
  935.     CA_DISCONNECTED,     // not talking to a server
  936.     CA_AUTHORIZING,        // not used any more, was checking cd key 
  937.     CA_CONNECTING,        // sending request packets to the server
  938.     CA_CHALLENGING,        // sending challenge packets to the server
  939.     CA_CONNECTED,        // netchan_t established, getting gamestate
  940.     CA_LOADING,            // only during cgame initialization, never during main loop
  941.     CA_PRIMED,            // got gamestate, waiting for first frame
  942.     CA_ACTIVE,            // game views should be displayed
  943.     CA_CINEMATIC        // playing a cinematic or a static pic, not connected to a server
  944. } connstate_t;
  945.  
  946.  
  947. #endif    // __Q_SHARED_H
  948.